/*
 * MouseEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Component;
import com.cute4j.swing.graphics.Point;

/**
 * Mouse Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class MouseEvent extends InputEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * Mouse clicked id.
   */
  public static final int MOUSE_CLICKED = 500;

  /**
   * Mouse pressed id.
   */
  public static final int MOUSE_PRESSED = 501;

  /**
   * Mouse released id.
   */
  public static final int MOUSE_RELEASED = 502;

  /**
   * Mouse moved id.
   */
  public static final int MOUSE_MOVED = 503;

  /**
   * Mouse entered id.
   */
  public static final int MOUSE_ENTERED = 504;

  /**
   * Mouse exited id.
   */
  public static final int MOUSE_EXITED = 505;

  /**
   * Mouse dragged id.
   */
  public static final int MOUSE_DRAGGED = 506;

  /**
   * Mouse wheel id.
   */
  public static final int MOUSE_WHEEL = 507;

  /**
   * Indicates that no button changed state.
   */
  public static final int NOBUTTON = 0;

  /**
   * Indicates that button 1 changed state.
   */
  public static final int BUTTON1 = 1;

  /**
   * Indicates that button 2 changed state.
   */
  public static final int BUTTON2 = 2;

  /**
   * Indicates button 3 changed state.
   */
  public static final int BUTTON3 = 3;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = -5568299749899765073L;

// Private Fields. -------------------------------------------------------------

  private int x;
  private int y;
  private int clickCount;
  private int button;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new MouseEvent object.
   *
   * @param source the source component
   * @param id the event id
   * @param when the time the event occurred
   * @param modifiers the modifiers
   * @param x the x coordinate of the mouse point
   * @param y the y coordinate of the mouse point
   * @param clickCount the click count
   * @param button the mouse button
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public MouseEvent(Component source, int id, long when, int modifiers, int x,
                    int y, int clickCount, int button) {
    super(source, id, when, modifiers);
    this.x = x;
    this.y = y;
    this.clickCount = clickCount;
    this.button = button;
  }

  /**
   * Constructs new MouseEvent object.
   *
   * @param source the source component
   * @param id the event id
   * @param when the time the event occurred
   * @param modifiers the modifiers
   * @param x the x coordinate of the mouse point
   * @param y the y coordinate of the mouse point
   * @param clickCount the click count
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public MouseEvent(Component source, int id, long when, int modifiers, int x,
                    int y, int clickCount) {
    this(source, id, when, modifiers, x, y, clickCount, NOBUTTON);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the x coordinate of the mouse position relative to the source
   * component.
   *
   * @return the x coordinate
   */
  public int getX() {
    return x;
  }

  /**
   * Returns the y coordinate of the mouse position relative to the source
   * component.
   *
   * @return the y coordinate
   */
  public int getY() {
    return y;
  }

  /**
   * Returns point of the mouse pointer relative to the source component.
   *
   * @return point of the mouse pointer
   */
  public Point getPoint() {
    return new Point(x, y);
  }

  /**
   * Returns click count.
   *
   * @return click count
   */
  public int getClickCount()  {
    return clickCount;
  }

  /**
   * Returns the button that changed state.
   *
   * @return the button that changed state
   */
  public int getButton() {
    return button;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    StringBuffer sb = new StringBuffer(80);
    switch (getID()) {
      case MOUSE_PRESSED:
        sb.append("MOUSE_PRESSED");
        break;
      case MOUSE_RELEASED:
        sb.append("MOUSE_RELEASED");
        break;
      case MOUSE_CLICKED:
        sb.append("MOUSE_CLICKED");
        break;
      case MOUSE_ENTERED:
        sb.append("MOUSE_ENTERED");
        break;
      case MOUSE_EXITED:
        sb.append("MOUSE_EXITED");
        break;
      case MOUSE_MOVED:
        sb.append("MOUSE_MOVED");
        break;
      case MOUSE_DRAGGED:
        sb.append("MOUSE_DRAGGED");
        break;
      case MOUSE_WHEEL:
        sb.append("MOUSE_WHEEL");
        break;
      default:
        sb.append("unknown type");
    }
    sb.append(",(");
    sb.append(getX());
    sb.append(',');
    sb.append(getY());
    sb.append("),button=");
    sb.append(getButton());
    int modifiers = getModifiers();
    if (modifiers != 0) {
      sb.append(",modifiers=");
      sb.append(getModifiersText(modifiers));
    }
    sb.append(",clickCount=");
    sb.append(getClickCount());
    return sb.toString();
  }

}
